Skip to content

Conversation

@ewlsh
Copy link

@ewlsh ewlsh commented Mar 27, 2025

Why am I submitting this PR

Internally we have code like this to fallback to '', but this trips up i18next-parser, which was reported in #634:

t(['cards.section.cta', ''], { fallbackLng: [] })

t(isAdmin ? 'admin.title' : '')

The PR aims to make the existing behavior consistent across files and --fail-on-update. I'm proposing this behind an option, but it could also just be done as the default behavior.

Details

This PR adds a new configuration option ignoreEmptyKeys (default: true) that controls whether empty keys should be ignored when scanning source files.

When set to true (default), empty keys in source files are ignored. These changes allows using t('') without false "Added keys" messages causing the failOnUpdate option to fail incorrectly.

When set to false, empty keys are included in the translation files. This is different from the current behavior, in this case adding '' will also cause failOnUpdate to fail which is the current behavior.

Does it fix an existing ticket?

Yes #634

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • do no modify the version in package.json or CHANGELOG.md
  • tests are included and pass: yarn test (see details here)
  • documentation is changed or added

This PR was generated with the help of https://www.all-hands.dev/ (an open source agent) but I have reviewed the code changes prior to submitting, updated the test suite, and adjusted this description to include additional context.

@ewlsh ewlsh changed the title Fix empty keys issue 634 Fix handling of empty keys Mar 27, 2025
@ewlsh ewlsh force-pushed the fix-empty-keys-issue-634 branch from 4951467 to 5d18f3e Compare March 27, 2025 14:45
@ewlsh ewlsh force-pushed the fix-empty-keys-issue-634 branch from 5d18f3e to aa53df6 Compare March 27, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant